function varargout = MEMC_MATTypeWnd(varargin)
% MEMC_MATTYPEWND M-file for MEMC_MATTypeWnd.fig
%      MEMC_MATTYPEWND, by itself, creates a new MEMC_MATTYPEWND or raises the existing
%      singleton*.
%
%      H = MEMC_MATTYPEWND returns the handle to a new MEMC_MATTYPEWND or the handle to
%      the existing singleton*.
%
%      MEMC_MATTYPEWND('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in MEMC_MATTYPEWND.M with the given input arguments.
%
%      MEMC_MATTYPEWND('Property','Value',...) creates a new MEMC_MATTYPEWND or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before MEMC_MATTypeWnd_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to MEMC_MATTypeWnd_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help MEMC_MATTypeWnd

% Last Modified by GUIDE v2.5 27-Jul-2010 00:13:24

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @MEMC_MATTypeWnd_OpeningFcn, ...
                   'gui_OutputFcn',  @MEMC_MATTypeWnd_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before MEMC_MATTypeWnd is made visible.
function MEMC_MATTypeWnd_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to MEMC_MATTypeWnd (see VARARGIN)
handles.tagMATFileName = '';
handles.MATFileID = '';
if nargin
   if isequal(varargin{1},'MATFileFullName')
       handles.tagMATFileName = varargin{2};
       handles.MATFileID = varargin{3};
   end
end  

% Choose default command line output for MEMC_MATTypeWnd
handles.output = hObject; % figure handle
handles.tagTypeText = [handles.tagTypeText1,   handles.tagTypeText2,...
                       handles.tagTypeText3,   handles.tagTypeText4,...
                       handles.tagTypeText5,   handles.tagTypeText6,...
                       handles.tagTypeText7,   handles.tagTypeText8,...
                       handles.tagTypeText9,   handles.tagTypeText10,...
                       handles.tagTypeText11,  handles.tagTypeText12,...
                       handles.tagTypeText13];

handles.hcmenu = CreateRightMouseMenu(handles.tagMATTypeFig);
handles.TypeCurSelected = {};
handles.TypeAllSelected = {};
handles.TypeAllScale = {};
handles.TypeAllBlend = {};
handles.nodeSizeType = {};
handles.TypeAllFileID = {}; 
handles.TypeAllImage = {};
handles.TextOffset = 0;
handles.TextIndex  = 1;

handles.root = {};
handles.picsize = [];
matdata  = load(handles.tagMATFileName);
matnames = fieldnames(matdata);
pos =ind2sub(size(matnames), strmatch('pic_size',matnames,'exact'));  
if pos == 0   %TBD Check
   msgbox('MAT Files Open','No ''pic_size'' is found in MAT file','error');
else    
   handles.picsize = getfield(matdata,'pic_size');
   handles.root = GenerateTreeNodes(matdata,1,{}); % handles.root
   handles.root = AddTreeAVINodes(handles.root); % add AVI node 
   handles.root_expand = length(handles.root);   
end

UpdateTypeStructAndText(handles,handles.root,0,0,1);
handles = UpdateSliderBehave(handles,handles.root_expand-length(handles.tagTypeText));

% Update handles structure
guidata(hObject, handles);
% UIWAIT makes MEMC_MATTypeWnd wait for user response (see UIRESUME)
uiwait(handles.tagMATTypeFig);

% --- Outputs from this function are returned to the command line.
function varargout = MEMC_MATTypeWnd_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
for k=1:length(handles.TypeAllImage)
    if handles.TypeAllImage{k} == 1
       handles.TypeAllFileID{k} = handles.TypeAllSelected{k};
       handles.TypeAllSelected{k} = {'AVI'};
    else
       handles.TypeAllFileID{k} =  handles.MATFileID;
    end
end
varargout{1} = handles.TypeAllSelected;
varargout{2} = handles.TypeAllScale;
varargout{3} = handles.TypeAllBlend;
varargout{4} = handles.TypeAllFileID;
varargout{5} = handles.picsize;
delete(hObject);

% --- Executes on slider movement.
function tagTypeSlider_Callback(hObject, eventdata, handles)
% hObject    handle to tagTypeSlider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of
%        slider
if isfield(handles,'holdon')
   if handles.holdon == 1
      return;
   end
end
handles.holdon = 1;
guidata(hObject, handles);

guidata(handles.tagMATTypeFig,handles);
range = handles.root_expand - length(handles.tagTypeText);
tmp = 0;
if range> 0
    tmp = ceil(range*(1-get(hObject,'Value')));
end
if handles.TextOffset ~= tmp
   handles.TextOffset = tmp;
   UpdateTypeStructAndText(handles,handles.root,0,0,1);
end

handles.holdon = 0;
guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function tagTypeSlider_CreateFcn(hObject, eventdata, handles)
% hObject    handle to tagTypeSlider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end
set(hObject,'Value',1);


% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over tagTypeText1.
function tagTypeText_ButtonDownFcn(hObject, eventdata, handles)
% hObject    handle to tagTypeText1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if isfield(handles,'holdon')
   if handles.holdon == 1
      return;
   end
end
handles.holdon = 1;
guidata(hObject, handles);

handles.TextIndex = find(handles.tagTypeText==hObject);
if strcmp(get(handles.tagMATTypeFig,'SelectionType'),'alt')  %normal/alt/extend
   [handles,handles.root,expands]=UpdateTypeStructAndText(handles,handles.root,1,0,1); % get handles.TypeCurSelected
elseif strcmp(get(handles.tagMATTypeFig,'SelectionType'),'normal')
   [handles,handles.root,expands] = UpdateTypeStructAndText(handles,handles.root,1,1,1);
   handles.root_expand = handles.root_expand + expands;
   handles = UpdateSliderBehave(handles,handles.root_expand-length(handles.tagTypeText));
end

handles.holdon = 0;
guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function tagTypeListsText_CreateFcn(hObject, eventdata, handles)
% hObject    handle to tagTypeListsText (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in tagMATTypeOK.
function tagMATTypeOK_Callback(hObject, eventdata, handles)
% hObject    handle to tagMATTypeOK (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
uiresume(handles.tagMATTypeFig);


% --- Executes when user attempts to close tagMATTypeFig.
function tagMATTypeFig_CloseRequestFcn(hObject, eventdata, handles)
% hObject    handle to tagMATTypeFig (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Hint: delete(hObject) closes the figure
handles.TypeAllSelected = {};
handles.TypeAllScale = {};
handles.TypeAllBlend = {};
handles.TypeAllFileID = {};
handles.ShownList = {};
handles.picsize = [];
guidata(handles.tagMATTypeFig,handles);
uiresume(handles.tagMATTypeFig);

%==========================================================================
function [handles] =  UpdateSliderBehave(handles,range)
isOn = 1;
preOn = 1;
isChange = 0;
tmp = get(handles.tagTypeSlider,'Enable');
if strcmp(tmp,'off') == 1
   preOn = 0;
end
if range <=0
   set(handles.tagTypeSlider,'Enable','off');
   if preOn == 1
      isChange = 1;
   end
   isOn = 0;
else
   set(handles.tagTypeSlider,'Enable','on');
   min = 1/range;
   max = 3*min;
   if max > 1
      max = min;
   end
   set(handles.tagTypeSlider,'SliderStep',[min max]);
   if preOn ~= 1
      isChange = 1;
   end
   isOn = 1;
end
if isOn == 0
   handles.TextOffset = 0;
end
tmp = 1-(handles.TextOffset/range);
if tmp <0
   tmp = 0;
elseif tmp>1
   tmp = 1;
end
preVal = get(handles.tagTypeSlider,'Value');
if preVal~=tmp
   set(handles.tagTypeSlider,'Value',tmp);
   UpdateTypeStructAndText(handles,handles.root,0,0,1);
end

%==========================================================================
% buide the tree
function root = GenerateTreeNodes(hireValue,level,topNames)
global GMATSrc;
NodesNames = fieldnames(hireValue);
root = {};
for k = 1:length(NodesNames)
    if level ~= 1 || ~isequal(NodesNames{k},'pic_size') %TBD: ignore 'pic_size'
       root(k).name = NodesNames(k);
       CurNames = {topNames{:},char(root(k).name)};
       tmpChildValue = getfield(hireValue,NodesNames{k});
       if isstruct(tmpChildValue)
          root(k).child = GenerateTreeNodes(tmpChildValue,level+1,CurNames);
          root(k).expand = 1;
          root(k).selected = 0;
          root(k).image = 0;
       else
          root(k).child = [];
          root(k).expand = 1;
          root(k).selected = 0;
          root(k).image = 0;
          GMATSrc = {GMATSrc{:},CurNames};
       end
    end
end

function root = AddTreeAVINodes(root)
global GP;
pos = [];
for k = 1:length(GP.SrcInfo)
    if isequal(char(GP.SrcInfo(k).Type),'AVI')
        pos = [pos,k];
    end
end
%pos = ind2sub(size({GP.SrcInfo.Type{1}}),strmatch('AVI',{GP.SrcInfo.Type{1}},'exact'));
for k = 1:length(pos)
    len = length(root)+1;
    root(len).name = GP.SrcInfo(k).szBaseName;
    root(len).child = [];
    root(len).expand = 1;
    root(len).selected = 0;
    root(len).image  = pos(k);
end
%========================================================================
% MAT Type Update and Drawing
function [handles,root,expands] = UpdateTypeStructAndText(handles,root,bSelect,bUpdate,level)
if level == 1
     handles.curLookIndex = 1;
     handles.nextLookIndex = 1;
     if bSelect == 0
        handles.TextIndex = 1;
     end
     handles.CurTextIndex = handles.TextOffset+ handles.TextIndex;
     handles.TypeCurSelected = {};
end
%find CurTextIndex
for k = 1:length(root)
   if handles.curLookIndex == handles.CurTextIndex
       if bUpdate==1
          expands= length(root(k).child);
          if root(k).expand ~= 1
             expands = -expands;
          end
          root(k).expand = root(k).expand + expands;
       else
          expands=0;
       end
       handles.CurTextIndex = handles.TextIndex;
       handles.TypeCurSelected = {handles.TypeCurSelected{:},char(root(k).name)};
       break;
    end
    handles.nextLookIndex = handles.curLookIndex + root(k).expand;
    if handles.nextLookIndex > handles.CurTextIndex
       handles.curLookIndex = handles.curLookIndex+1;
       handles.TypeCurSelected = {handles.TypeCurSelected{:},char(root(k).name)};
       [handles,root(k).child,expands] = UpdateTypeStructAndText(handles,root(k).child,bSelect,bUpdate,level+1);
       root(k).expand = root(k).expand + expands;
       k = k+1;
       break,
    end
    handles.curLookIndex = handles.nextLookIndex;
end

%Update the Text
while k <= length(root) && handles.CurTextIndex <= length(handles.tagTypeText)
  SetOneTypeText(root(k),handles,level);
  handles.CurTextIndex = handles.CurTextIndex + 1;
  if handles.CurTextIndex <= length(handles.tagTypeText) && root(k).expand > 1
     handles = UpdateTypeText(handles,root(k).child,level+1);
  end
  k = k + 1;
end
if level == 1
    while handles.CurTextIndex <= length(handles.tagTypeText)
        set(handles.tagTypeText(handles.CurTextIndex),'String','');
        handles.CurTextIndex = handles.CurTextIndex + 1;
    end
end

%------------------------------------------------------------
function handles = UpdateTypeText(handles,root,level)
k = 1;
while k <= length(root) && handles.CurTextIndex <= length(handles.tagTypeText)
   SetOneTypeText(root(k),handles,level);
   handles.CurTextIndex = handles.CurTextIndex + 1;
   if handles.CurTextIndex <= length(handles.tagTypeText) && root(k).expand > 1
      handles = UpdateTypeText(handles,root(k).child,level+1);
   end
   k = k+1;
end
%-------------------------------------------------------------
function SetOneTypeText(node,handles,level)
color = [0,0,0];
if node.selected == 1
     color = [1,0,0];
end
set(handles.tagTypeText(handles.CurTextIndex),'ForegroundColor',color);
space = zeros(1,(level-1)*6);
space(:) = ' ';
if isempty(node.child)
   szText  = sprintf('%s%s',char(space),char(node.name));
elseif node.expand > 1
   szText  = sprintf('%s-%s',char(space),char(node.name)); 
else   
   szText  = sprintf('%s+%s',char(space),char(node.name)); 
end
set(handles.tagTypeText(handles.CurTextIndex),'String',szText);
if isempty(node.child)
   set(handles.tagTypeText(handles.CurTextIndex),'uicontextmenu',handles.hcmenu); 
end

%==========================================================================
function hmenu = CreateRightMouseMenu(hFigure)
hmenu = uicontextmenu;
% Define the context menu items and install their callbacks
uimenu(hmenu, 'UserData',hFigure,'Label', 'Add this data to Analysis', 'Callback', @AddOneTypeFunc);
uimenu(hmenu, 'UserData',hFigure,'Label', 'Delete', 'Callback', @DeleteOneTypeFunc);

%-------------------------------------------------------
function nodeSizeType = GetNodeSizeType(handles)
val = load(handles.tagMATFileName,handles.TypeCurSelected{1});
for k = 1:length(handles.TypeCurSelected)
    val = getfield(val,handles.TypeCurSelected{k});
end
tmpSize = size(val);
if length(tmpSize)<2 || length(tmpSize)>3
    nodeSizeType = 0;
elseif length(tmpSize) == 2 
    nodeSizeType = 1;
    if tmpSize(1)<2 || tmpSize(2)<2
       nodeSizeType = 0;
    end
else
    nodeSizeType = tmpSize(3); 
    if tmpSize(3)<2 || tmpSize(3)>3
        nodeSizeType = 0;
    end
end
%----------------------------------------------------------
function AddOneTypeFunc(hObject, eventdata)
handles = guidata(get(hObject,'UserData'));
if isfield(handles,'holdon')
   if handles.holdon == 1
      return;
   end
end
handles.holdon = 1;
guidata(hObject, handles);

k = 1;
while k<=length(handles.root)
  if isequal(char(handles.root(k).name),handles.TypeCurSelected{1})
     if handles.root(k).image == 1
        break;
     end
  end
  k=k+1;
end
if k>length(handles.root)
   nodeSizeType = GetNodeSizeType(handles);
else
   nodeSizeType = -1; %Image
end
if nodeSizeType ~= 0 || nodeSizeType == -1
   k = 1;
   while k<=length(handles.TypeAllSelected)
     if isequal(handles.TypeAllSelected{k},handles.TypeCurSelected)
         break;
      end
      k = k+1;
   end
   if k>length(handles.TypeAllSelected)
      handles.TypeAllSelected{k} = handles.TypeCurSelected;
      handles.TypeAllBlend{k} = [1,1,1];
      handles.nodeSizeType{k} = nodeSizeType;
      if nodeSizeType == 1
         handles.TypeAllScale{k} = 1;
      elseif nodeSizeType==2
         handles.TypeAllScale{k} = [1,1];
      else
         handles.TypeAllScale{k} = []; 
      end
      if nodeSizeType == -1
         handles.TypeAllImage{k} = 1;
      else
         handles.TypeAllImage{k} = 0; 
      end
      % for Show list
      handles.ShownList{k} =  GetShownListString(handles,k);
      %UpdateTypeLists(handles);
      handles.root = SetTreeNodeSelected(handles.root,handles.TypeCurSelected,1);
      UpdateTypeStructAndText(handles,handles.root,0,0,1);
      set(handles.tagTypeListsText,'String',handles.ShownList);
   end
end
   
handles.holdon = 0;
guidata(hObject, handles);

%-----------------------------------------------------
function DeleteOneTypeFunc(hObject, eventdata)
handles = guidata(get(hObject,'UserData'));
if isfield(handles,'holdon')
   if handles.holdon == 1
      return;
   end
end
handles.holdon = 1;
guidata(hObject, handles);

TypeListLen = length(handles.TypeAllSelected);
k = 1;
while k<=TypeListLen
  if isequal(handles.TypeAllSelected{k},handles.TypeCurSelected)
      break;
  end
  k = k+1;
end
if (k <= TypeListLen)
   if TypeListLen == 1
       handles.TypeAllSelected = {};
       handles.TypeAllScale   = {};
       handles.TypeAllImage   = {};
       handles.TypeAllBlend   = {};
       handles.nodeSizeType   = {};
       handles.ShownList      = {};
   elseif k == TypeListLen
       handles.TypeAllSelected = handles.TypeAllSelected(1:k-1);
       handles.TypeAllScale    = handles.TypeAllScale(1:k-1);
       handles.TypeAllImage    = handles.TypeAllImage(1:k-1);
       handles.TypeAllBlend    = handles.TypeAllBlend(1:k-1);
       handles.nodeSizeType    = handles.nodeSizeType(1:k-1);
       hanldes.ShownList       = handles.ShownList(1:k-1);
   elseif k == 1
       handles.TypeAllSelected = handles.TypeAllSelected(2:TypeListLen);
       handles.TypeAllScale = handles.TypeAllScale(2:TypeListLen);
       handles.TypeAllImage = handles.TypeAllImage(2:TypeListLen);
       handles.TypeAllBlend = handles.TypeAllBlend(2:TypeListLen);
       handles.nodeSizeType = handles.nodeSizeType(2:TypeListLen);
       handles.ShownList    = handles.ShownList(2:TypeListLen);
   else
       handles.TypeAllSelected = [handles.TypeAllSelected(1:k-1),handles.TypeAllSelected(k+1:TypeListLen)];
       handles.TypeAllScale    = [handles.TypeAllScale(1:k-1),handles.TypeAllScale(k+1:TypeListLen)];
       handles.TypeAllImage    = [handles.TypeAllImage(1:k-1),handles.TypeAllImage(k+1:TypeListLen)];
       handles.TypeAllBlend    = [handles.TypeAllBlend(1:k-1),handles.TypeAllBlend(k+1:TypeListLen)];
       handles.nodeSizeType    = [handles.nodeSizeType(1:k-1),handles.nodeSizeType(k+1:TypeListLen)];
       handles.ShownList       = [handles.ShownList(1:k-1),handles.ShownList(k+1:TypeListLen)];
   end
   %UpdateTypeLists(handles);
   handles.root = SetTreeNodeSelected(handles.root,handles.TypeCurSelected,0);
   UpdateTypeStructAndText(handles,handles.root,0,0,1);
   set(handles.tagTypeListsText,'String',handles.ShownList);
end
handles.holdon = 0;
guidata(hObject, handles);

%-------------------------------------------------
function root = SetTreeNodeSelected(root,NodeTree,bSelected)
for k = 1:length(root)
    if isequal(char(root(k).name),NodeTree{1})
       if length(NodeTree) == 1
          root(k).selected = bSelected;
       else
          root(k).child = SetTreeNodeSelected(root(k).child,NodeTree(2:length(NodeTree)),bSelected);
       end
    end
end

%-------------------------------------------------------
function ListString = GetShownListString(handles,idx)
ListString = sprintf('%s',handles.TypeAllSelected{idx}{1});
for k = 2:length(handles.TypeAllSelected{idx})
     ListString = sprintf('%s.%s',ListString,handles.TypeAllSelected{idx}{k});
end
len = 40-length(ListString);
if len<1
   len = 1;
end
space = zeros(1,len);
space(:) = ' ';
ListString = sprintf('%s%s',ListString,char(space));
%scale
scaleLen = length(handles.TypeAllScale{idx});
if  scaleLen == 1
    ListString = sprintf('%s scale:[Scald]=[%g]',ListString,handles.TypeAllScale{idx}(1));
elseif scaleLen == 2
    ListString = sprintf('%s scale:[Scaly,Scaluv]=[%g,%g]',ListString,handles.TypeAllScale{idx}(1),handles.TypeAllScale{idx}(2));
end
%blend
if ~isempty(handles.TypeAllSelected)
   len = 70-length(ListString);
   if len<1
      len = 1;
   end
   space = zeros(1,len);
   space(:) = ' ';
   ListString = sprintf('%s%s',ListString,char(space));
   ListString = sprintf('%sblend:[%g,%g,%g]',ListString,handles.TypeAllBlend{idx}(1),...
                                handles.TypeAllBlend{idx}(2),handles.TypeAllBlend{idx}(3));
end


% --- Executes on selection change in tagTypeListsText.
function tagTypeListsText_Callback(hObject, eventdata, handles)
% hObject    handle to tagTypeListsText (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns tagTypeListsText contents as cell array
%        contents{get(hObject,'Value')} returns selected item from
%        tagTypeListsText
if isfield(handles,'holdon')
   if handles.holdon == 1
      return;
   end
end
handles.holdon = 1;
guidata(hObject, handles);

Selected = get(hObject,'Value');

tmpStr = sprintf('%s',handles.TypeAllSelected{Selected}{1});
for k = 2:length(handles.TypeAllSelected{Selected})
    tmpStr = sprintf('%s.%s',tmpStr,handles.TypeAllSelected{Selected}{k});
end

if length(handles.TypeAllSelected)<2 && handles.nodeSizeType{Selected} == -1
    handles.holdon = 0;
    guidata(hObject, handles);
    return;
end

bBlendEnable = 1;
[handles.TypeAllScale{Selected},handles.TypeAllBlend{Selected}] = MEMC_MATScaleWnd('TypeName',tmpStr,handles.nodeSizeType{Selected},...
                                                    handles.TypeAllScale{Selected},handles.TypeAllBlend{Selected},bBlendEnable);
handles.ShownList{Selected} =  GetShownListString(handles,Selected);
set(handles.tagTypeListsText,'String',handles.ShownList);

handles.holdon = 0;
guidata(hObject, handles);
